package db.op.web;

import db.DBUtils;
import functions.web.Login;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.EncryUtils;

/**
 *
 * @author meluo
 * @data Expression Data is undefined on line 8, column 12 in
 * Templates/Classes/Class.java.
 */
public class LoginOP extends DBUtils{
    private Login login; 

    public LoginOP(Login absf) {
        this.login= absf;
    }
    public Map op() {
    //  long key=System.currentTimeMillis()/1000000;

      Map<String,Object> map=new HashMap<>();
      map.put("status", false);
        try {
        String sql="SELECT * FROM users where user_email=?";
        PreparedStatement prp= getConnection().prepareStatement(sql);
        prp.setString(1,login.getUserEmail());
        ResultSet rest=prepareExecuteQuery(prp);
        while(rest.next()){
            String b=rest.getString("user_password");
         //   String pass=EncryUtils.md5(b+key);
            if(b.equals(login.getPassword())){
              map.put("status", true);
              map.put("userKey",rest.getString("user_key"));
            }
        }
        } catch (SQLException ex) {
             Logger.getLogger(DBUtils.class.getName()).log(Level.SEVERE, null, ex);
              map.put("status", false);
        }
        
        return map;
    }

}
